#include "FSQ.h"

#include "XVulkan.h"

FSQ::FSQ()
{
}

FSQ::~FSQ()
{
    delete mVertexBuffer;
}

void FSQ::Init()
{
    mVertexBuffer = new VertexBuffer();
    mVertexBuffer->SetSize(4);
    mVertexBuffer->SetPosition(0, -1.0f, 1.0f, 0.0f);
    mVertexBuffer->SetTexcoord(0, 0.0f, 0.0f, 0.0f);
    mVertexBuffer->SetPosition(1, 1.0f, 1.0f, 0.0f);
    mVertexBuffer->SetTexcoord(1, 1.0f, 0.0f, 0.0f);
    mVertexBuffer->SetPosition(2, -1.0f, -1.0f, 0.0f);
    mVertexBuffer->SetTexcoord(2, 0.0f, 1.0f, 0.0f);
    mVertexBuffer->SetPosition(3, 1.0f, -1.0f, 0.0f);
    mVertexBuffer->SetTexcoord(3, 1.0f, 1.0f, 0.0f);
    mVertexBuffer->SubmitData();
}

void FSQ::Draw(VkCommandBuffer commandBuffer)
{
    xSetDynamicState(mMaterial->mFixedPipeline, commandBuffer);

    VkBuffer vertexBuffers[] = {mVertexBuffer->mBuffer};
    VkDeviceSize offsets[] = {0};

    vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, mMaterial->mFixedPipeline->mPipeline);
    vkCmdBindVertexBuffers(commandBuffer, 0, 1, vertexBuffers, offsets);

    vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, mMaterial->mFixedPipeline->mPipelineLayout, 0, 1, &mMaterial->mProgram.mDescriptorSet, 0,
                            nullptr);

    vkCmdDraw(commandBuffer, 4, 1, 0, 0);
}
